package configs

import "time"

// 数据库配置
func GetDbConfig() map[string]string {
	// 初始化数据库配置map
	dbConfig := make(map[string]string)

	dbConfig["DB_HOST"] = "154.209.69.12"
	dbConfig["DB_PORT"] = "33306"
	dbConfig["DB_NAME"] = "test"
	dbConfig["DB_USER"] = "root"
	dbConfig["DB_PWD"] = "123456"
	dbConfig["DB_CHARSET"] = "utf8"
	dbConfig["DB_LOC"] = "Local"
	dbConfig["DB_PARSETIME"] = "True"

	dbConfig["DB_MAX_OPEN_CONNS"] = "20"       // 连接池最大连接数
	dbConfig["DB_MAX_IDLE_CONNS"] = "10"       // 连接池最大空闲数
	dbConfig["DB_MAX_LIFETIME_CONNS"] = "7200" // 连接池链接最长生命周期

	return dbConfig
}

/** 集群配置
{
	"master":{
		"host": "",
		"port": "",
		"user": "",
		"name" : "",
		"password" : "",
		"loc" : "",
		...
	},
	"slave1":{},
	"slave2":{}

}

node 默认设置3个节点减少内存动态开辟的资源
*/
func GetDBClusterConfig() map[string]map[string]string {
	// 初始化数据库配置map
	// TemPoraryNode := "127.0.0.1"
	// TemPoraryPort := "3306"
	// server
	TemPoraryNode := "192.168.30.63"
	// TemPoraryPort := "33306"

	dbConfig := map[string]map[string]string{
		"master": {
			"DB_HOST": TemPoraryNode,
			// "DB_PORT": TemPoraryPort,
			"DB_PORT":               "3306",
			"DB_NAME":               "account",
			"DB_USER":               "root",
			"DB_PWD":                "123456",
			"DB_CHARSET":            "utf8",
			"DB_LOC":                "Local",
			"DB_PARSETIME":          "True",
			"DB_MAX_OPEN_CONNS":     "20",
			"DB_MAX_IDLE_CONNS":     "10",
			"DB_MAX_LIFETIME_CONNS": "7200",
		},
		"slave1": {
			"DB_HOST": TemPoraryNode,
			// "DB_PORT": TemPoraryPort,
			"DB_PORT":               "3316",
			"DB_NAME":               "account",
			"DB_USER":               "root",
			"DB_PWD":                "123456",
			"DB_CHARSET":            "utf8",
			"DB_LOC":                "Local",
			"DB_PARSETIME":          "True",
			"DB_MAX_OPEN_CONNS":     "20",
			"DB_MAX_IDLE_CONNS":     "10",
			"DB_MAX_LIFETIME_CONNS": "7200",
		},
		"slave2": {
			"DB_HOST": TemPoraryNode,
			// "DB_PORT": TemPoraryPort,
			"DB_PORT":               "3326",
			"DB_NAME":               "account",
			"DB_USER":               "root",
			"DB_PWD":                "123456",
			"DB_CHARSET":            "utf8",
			"DB_LOC":                "Local",
			"DB_PARSETIME":          "True",
			"DB_MAX_OPEN_CONNS":     "20",
			"DB_MAX_IDLE_CONNS":     "10",
			"DB_MAX_LIFETIME_CONNS": "7200",
		},
	}
	return dbConfig

}

/** redis集群配置
{
	"node":{
		"host": "",
		"port": "",
		"user": "",
		"name" : "",
		"password" : "",
		"loc" : "",
		...
	},
	"node":{},
	"node":{}

}

node 默认设置3个节点减少内存动态开辟的资源
*/
func GetRedisClusterConfig() (node map[string]map[string]interface{}) {

	// NODE_HOST := "154.209.69.12"
	NODE_HOST := "192.168.30.63"

	node = map[string]map[string]interface{}{
		"node": {
			"host": []string{
				NODE_HOST + ":7001",
				NODE_HOST + ":7002",
				NODE_HOST + ":7003",
				NODE_HOST + ":7004",
				NODE_HOST + ":7005",
				NODE_HOST + ":7006",
			},
			"dialTimeout":  50 * time.Millisecond,
			"readTimeout":  50 * time.Millisecond,
			"writeTimeout": 50 * time.Millisecond,
			"poolSize":     16,
			"maxConnAge":   60 * time.Second,
		},
	}
	return
}

// Redis 单机版测试
func GetRedisNodeConfig() (node map[string]map[string]string) {
	NODE_HOST := "154.209.69.12:7006"
	// NODE_HOST := "127.0.0.1:6379"
	NODE_PASSWORD := ""
	NODE_DB := "0"

	node = map[string]map[string]string{
		"node": {
			"host":     NODE_HOST,
			"password": NODE_PASSWORD,
			"db":       NODE_DB,
		},
	}
	return
}

/*
	注意修改的文件中的单点配值
			server/account.go
			server/component/balance.go
*/

// 加载Reids开关
func RedisSelectNodeOrCluster() bool {
	isClusterNode := true
	return isClusterNode
}

// 加载开关
func DBSelectNodeOrCluster() bool {
	isClusterNode := true
	return isClusterNode
}
